/*
* @Author: chenggh
* @Date: 2025-06-21
* @Link to Problem : https://webvpn.neu.edu.cn/https/62304135386136393339346365373340bfebea318fd008d8f60d257088/courses/27/part/222/problem/1006
k == 1的大问题
*/
#include <iostream>
#include <set>
using ll = long long;
using namespace std;
class MedianStreamFinder{
private:
	multiset<ll> lowerheap, upperheap;
	ll sum_lower, sum_upper;
	ll k;
	void update(){
		while(lowerheap.size() > upperheap.size()){
			auto it = lowerheap.begin();
			ll temp = - *it; // 正数
			lowerheap.erase(it);
			sum_lower -= temp;
			upperheap.insert(temp);
			sum_upper += temp;
		}
		while(lowerheap.size() < upperheap.size() - 1){
			auto it = upperheap.begin();
			ll temp = - *it;
			upperheap.erase(it);
			sum_upper += temp;
			lowerheap.insert(temp);
			sum_lower -= temp;
		}
		return;
	}
public:
	MedianStreamFinder(ll k):sum_lower(0),sum_upper(0), k(k){} 
	void add_num(ll num){
		if(upperheap.empty() || num >= *upperheap.begin()){
			upperheap.insert(num);
			sum_upper += num;
		}else {
			lowerheap.insert(-num);
			sum_lower += num;
		}
		update();
	}
	ll get_median_upper(){
		return *upperheap.begin();
	}
	void pop(ll num) {
        auto it_upper = upperheap.find(num);
        if (it_upper != upperheap.end()) {
            upperheap.erase(it_upper);
            sum_upper -= num;
        } else {
            auto it_lower = lowerheap.find(-num);
            if (it_lower != lowerheap.end()) { // <-- 必须加上这个检查！
                lowerheap.erase(it_lower);
                sum_lower -= num;
            }
        }
        update();
    }
	ll get_cost(){
		ll median = get_median_upper();
		ll ans = 0;
		ans += (sum_upper - (k + 1) / 2 * median);
		ans += ((k / 2) * median - sum_lower);
		return ans;
	}
};
#include <vector>
int32_t main(){

	int n, k;
    cin >> n >> k;
    // 1. 一次性读入所有数据，逻辑清晰
	vector<int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}cout << endl;

	MedianStreamFinder finder(k);

	if(k == 1){
		for(int i = 0; i < n; i++){
			if(i) cout << " ";
			cout << "0" ;
		}cout << endl;
		return 0;
	}

    // 2. 建立第一个窗口
	for(int i = 0; i < k; i++){
		finder.add_num(v[i]);
	}
	cout << finder.get_cost();

    // 3. 标准的滑动窗口循环
	for(int i = k; i < n; i++){
        // a. 移除旧的 (窗口最左边)
		finder.pop(v[i - k]);
        // b. 加入新的 (窗口最右边)
		finder.add_num(v[i]);
        // c. 计算并输出
		cout << " " << finder.get_cost();
	}
	cout << endl;
	
	return 0;
}